package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo1 {
    public static void main(String[] args)throws Exception {
    Class.forName("com.mysql.cj.jdbc.Driver");
        /**
            JDBC操作数据库的基本流程
            1:加载驱动
            2:使用驱动管理器建立链接
            3:通过链接创建语句对象
            4:使用语句对象执行SQL语句
            5:如果执行DQL则得到查询结果集
            6:遍历查询结果集
            7:关闭链接
         */
        Connection connection = DriverManager.getConnection(
                                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                                "root",
                                "root");
        System.out.println("链接");
        //3创建语句对象
        Statement statement = connection.createStatement();
        /**
         * 创建：userinfo
         * CREATE TABLE userinfo(
         *        id INT PRIMARY KEY AUTO_INCREMENT,
         *        username VARCHAR(30),
         *        password VARCHAR(30),
         *        nickname VARCHAR(30),
         *        age INT(3)
         *       );
         */

        String sql ="CREATE TABLE userinfo("+
                "        id INT PRIMARY KEY AUTO_INCREMENT,"+
                "        username VARCHAR(30),"+
                "        password VARCHAR(30),"+
                "        nickname VARCHAR(30),"+
                "        age INT(3)"+
                ")";
        statement.execute(sql);
        System.out.println("创建完了");

        connection.close();
    }
}
